package com.schoolET.controller.admin;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.schoolET.entity.dto.OrderManagementDTO;
import com.schoolET.result.MyPage;
import com.schoolET.result.Result;
import com.schoolET.service.IOrderManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "查看订单信息")
@RestController
@RequestMapping("/schoolET")
public class OrderSendController {

    @Autowired
    private IOrderManagementService orderManagementservice;

    @PostMapping("/orderSend")
    @ApiOperation(value = "查询交易中的订单")
    @SaCheckLogin
    @SaCheckRole("region-admin")
    public Result orderSend(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                            @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
        // 检查pageNum是否为负数，如果是，则设为默认值1
        pageNum = pageNum < 0 ? 1 : pageNum;
        // 检查pageSize是否为负数，如果是，则设为默认值5
        pageSize = pageSize < 0 ? 5 : pageSize;
        Page<OrderManagementDTO> orderManagement = orderManagementservice.getOrderManagement(pageNum, pageSize);
        return Result.success(MyPage.page(orderManagement)).msg("查询完成");
    }
}
